package cn.com.zt.activity.scan

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import cn.com.zt.databinding.ActivityQrCodeBinding

/**
 * date:2021/6/18
 * author:zhangteng
 * description:二维码扫描
 */
class QRCodeActivity : AppCompatActivity() {
    private lateinit var binding: ActivityQrCodeBinding
    private val mHandler = Handler(Looper.getMainLooper())

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityQrCodeBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initController()
    }

    private fun initController() {
        binding.cameraView.bindToLifecycle(this, object : CameraXScanView.OnResultAndFlashListener {
            override fun onResult(result: String) {
//                val intent = Intent(this@QRCodeActivity, QRCodeResultActivity::class.java)
//                intent.putExtra(QRCodeResultActivity.RESULT_KEY, result)
//                startActivity(intent)
//                finish()
                Toast.makeText(this@QRCodeActivity, "" + result, Toast.LENGTH_SHORT).show()
            }

            override fun onFlashLightStatusCallback(isOpen: Boolean) {

            }
        })
        binding.cameraView.startOneScan()
    }

}